﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Filters;

namespace webui.Filters
{
    public class ApiErrorAttribute : ExceptionFilterAttribute
    {
        /// <summary>
       /// 重写异常处理方法 add by caoheyang 20150205
      /// </summary>
      /// <param name="filterContext">上下文对象</param>
        public override void OnException(HttpActionExecutedContext filterContext)
        {
            try
            {
                string ErrorMsg = string.Format("API异常：" + filterContext.Exception.StackTrace);
                ErrorMsg += "     \r\n异常信息：" + filterContext.Exception.ToString();
                Logger.Default.Error(ErrorMsg);//用Nlog记录日志
            }
            catch(Exception ce)
            {
                string s1 = filterContext.Exception.Message;
                s1 += filterContext.Exception.StackTrace;
                Tools.CommonHellper.WriteLog(s1 + "   222错误222 " + ce.Message);
            }
               

             
        }

    }
}